#! /usr/bin/env python
# -*- coding: utf-8 -*-

area_name = '液氨罐区'
area_id = 'e34e2b52c8b74928a82485e436be3717'
device_name = '液氨储罐1'
device_id = 'e146c6dbb5784073a7e69f5cdc50262f'
alarm_status = '正常'  # extinguished_alarm
alarm_status_key = 'extinguished_alarm'
danger_type = '罐区'  # 0
danger_type_key = 0
danger_level = '二级'  # 2
danger_level_key = 2
danger_name = '测试重大危险源-xmj'
danger_id = '测试重大危险源-xmj'

query_sql = '''
select count(*) from (
SELECT
	mmmi.id
FROM
	hgyq_major_hazard_sources.mw_m_monitor_index mmmi
	LEFT JOIN hgyq_major_hazard_sources.mw_m_alarm_info mmai ON mmmi.id = mmai.alarm_index_id 
WHERE
	mmmi.is_deleted = 0 
	AND mmmi.area_moid = "''' + area_id + '''" 
	AND mmmi.object_moid = "''' + device_id + '''" 
	AND mmmi.major_hazard_id IN ( SELECT id FROM hgyq_synthetical.ha_m_great_risk_bill 
	WHERE type = ''' + str(danger_type_key) + ''' AND LEVEL = ''' + str(
    danger_level_key) + ''' AND NAME LIKE "%''' + danger_name + '''%"
	 ) 
	AND mmai.alarm_status = "''' + alarm_status_key + '''" 
ORDER BY
	mmai.alarm_time DESC 
	LIMIT 1
) t
'''
